<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目延期申请管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid"
			data-options="
				rownumbers:true,
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'applyPersonName',width:80,align:'center'">申请人</th>
				<th data-options="field:'applyTime',width:120,align:'center'">申请时间</th>
				<th data-options="field:'checkPersonName',width:80,align:'center'">审核人</th>
				<th data-options="field:'checkTime',width:120,align:'center'">审核时间</th>
				<th data-options="field:'ratifyPersonName',width:80,align:'center'">审核人</th>
				<th data-options="field:'ratifyTime',width:120,align:'center'">审批时间</th>
				<th data-options="field:'status',width:80,align:'center'">状态</th>
				<th data-options="field:'id',width:100,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="initAddItem()">新增延期</a>
		</div>
		<div>
			申请时间: <input class="easyui-datebox" type="text" id="applyTimeBegin" style="width:100px;height:25px;">
			~ <input class="easyui-datebox" type="text" id="applyTimeEnd" style="width:100px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="项目延期申请详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:660px; height:480px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
						<tr>
							<td width="130px;" align="right">原完成日期：</td>
							<td>
								<input class="easyui-datetimebox" id="lookOriginalFinishDate" style="width: 150px;" readonly="readonly" />
							</td>
							<td width="130px;" align="right">目标完成日期：</td>
							<td>
								<input class="easyui-datetimebox" id="lookTargetFinishDate" style="width: 150px;" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">状态：</td>
							<td width="160px">
								<input class="easyui-textbox" id="lookStatus" style="width: 150px;" readonly="readonly" />
							</td>
							<td align="right">申请时间：</td>
							<td>
								<input class="easyui-datetimebox" id="lookApplyTime" style="width: 150px;" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">申请理由：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 500px; height: 80px;" id="lookApplyReason" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">审核人：</td>
							<td>
								<input class="easyui-textbox" id="lookCheckPersonId" style="width: 150px;" readonly="readonly" />
							</td>
							<td align="right">审核时间：</td>
							<td>
								<input class="easyui-datetimebox" id="lookCheckTime" style="width: 150px;" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">审核意见：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 500px; height: 80px;" id="lookCheckComment" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">复核人：</td>
							<td>
								<input class="easyui-textbox" id="lookRatifyPersonId" style="width: 150px;" readonly="readonly" />
							</td>
							<td align="right">复核时间：</td>
							<td>
								<input class="easyui-datetimebox" id="lookRatifyTime" style="width: 150px;" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">复核意见：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 500px; height: 80px;" id="lookRatifyComment" readonly="readonly" />
							</td>
						</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="新增项目延期申请" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:260px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editProjectDelayApply" style = "width:100%; height: 100%">
					<input type="hidden" name="status" value="0200" id="addStatus" />
					<input type="hidden" name="project.id" value="${project.id }" id="addProjectId" />
					<input type="hidden" name="project.status" value="0200" id="addProjectStatus" />
					<table width="100%" height="100%">
						<tr>
							<td width="130px;" align="right">原完成日期：</td>
							<td>
								<input class="easyui-datebox" name="originalFinishDate" id="addoriginalFinishDate" data-options="required:true" style="width: 180px;" readonly="readonly" />
							</td>
							<td width="130px;" align="right">目标完成日期：</td>
							<td>
								<input class="easyui-datebox" name="targetFinishDate" data-options="required:true" style="width: 180px;" />
							</td>
						</tr>
						<tr>
							<td align="right">申请理由：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 500px; height: 120px;" name="applyReason">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="编辑项目延期申请" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:260px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editProjectDelayApply" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<input type="hidden" name="project.id" value="${project.id }" id="editProjectId" />
					<input type="hidden" name="status" value="0200" id="editStatus" />
					<input type="hidden" name="applyTime" id="editApplyTime" />
					<input type="hidden" name="applyPerson.id" value="${currentUser.id }" id="editApplyPersonId" />
					<table width="100%" height="100%">
						<tr>
							<td width="130px;" align="right">原完成日期：</td>
							<td>
								<input class="easyui-datebox" name="originalFinishDate" id="editOriginalFinishDate" data-options="required:true" style="width: 180px;" />
							</td>
							<td width="130px;" align="right">目标完成日期：</td>
							<td>
								<input class="easyui-datebox" name="targetFinishDate" id="editTargetFinishDate" data-options="required:true" style="width: 180px;" />
							</td>
						</tr>
						<tr>
							<td align="right">申请理由：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 500px; height: 80px;" name="applyReason" id="editApplyReason">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			var content = '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + row.id + ')">查看</a>';
			if(row.statusCode == '0200'){
				content += ' <a class="ctl" href="javascript:void(0)" onclick="revocationDelayApplyProjectDelayApply(' + val + ')">撤销延期</a>';
			}
			return content;
		}
		function search(){
			var applyTimeBegin = $("#applyTimeBegin").textbox("getValue").trim();
			var applyTimeEnd = $("#applyTimeEnd").textbox("getValue").trim();
			var url = "queryProjectDelayApply?projectId=${project.id}&applyTimeBegin=" + applyTimeBegin + "&applyTimeEnd=" + applyTimeEnd;
			$("#dg").datagrid('reload', url);
		}
		function lookDetail(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findProjectDelayApply",
			  	data: params,
			  	success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#lookApplyPersonId").textbox("setValue", item.applyPersonName);
						$("#lookCheckPersonId").textbox("setValue", item.checkPersonName);
						$("#lookRatifyPersonId").textbox("setValue", item.ratifyPersonName);
						$("#lookOriginalFinishDate").textbox("setValue", item.originalFinishDate);
						$("#lookTargetFinishDate").textbox("setValue", item.targetFinishDate);
						$("#lookApplyTime").textbox("setValue", item.applyTime);
						$("#lookApplyReason").textbox("setValue", item.applyReason);
						$("#lookCheckTime").textbox("setValue", item.checkTime);
						$("#lookCheckComment").textbox("setValue", item.checkComment);
						$("#lookRatifyTime").textbox("setValue", item.ratifyTime);
						$("#lookRatifyComment").textbox("setValue", item.ratifyComment);
						$("#lookStatus").textbox("setValue", item.status);
						
						$('#lookDetail').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function editItem(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findProjectDelayApply",
			  	data: params,
			  	success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#editId").val(id);
						$("#editProjectId").val(item.projectId);
						$("#editStatus").val(item.status);
						$("#editApplyPersonId").val(item.applyPersonId);
						$("#editApplyTime").val(item.applyTime);
						$("#editOriginalFinishDate").textbox("setValue", item.originalFinishDate);
						$("#editTargetFinishDate").textbox("setValue", item.targetFinishDate);
						$("#editApplyReason").textbox("setValue", item.applyReason);
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
			
			$('#editItem').window('open');
		}
		function revocationDelayApplyProjectDelayApply(id){
			$.messager.confirm("撤销项目延期确认", "您确定要撤销所选的项目延期申请吗？", function(r){
				if(r){
					data = "id=" + id + "&status=0070&project.status=0055";
					$.ajax({
					  type: "POST",
					  url: "revocationDelayApplyProjectDelayApply",
					  data: data,
					  success:function(data){
						  	var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '删除成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  }
					});
				}
			});
		}
		function initAddItem(){
			clearForm('form', 'addItem');
			$('#addProjectId').val('${project.id}');
			$('#addStatus').val('0200');
			$('#addProjectStatus').val('0200');
			
			$('#addoriginalFinishDate').textbox('setValue', '${project.planFinishDate}');
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '添加成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '修改成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			search();//页面装载完成后加载数据
		});
	</script>
</body>
</html>